﻿using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using System.Net;
using System.IO;

namespace ProjectBase.Guidance.Helpers
{
    public static class SourceControlHelper
    {
        public static void Checkout(DTE vs, string itemPath)
        {
            try
            {
                FileAttributes attributes = File.GetAttributes(itemPath) & FileAttributes.ReadOnly;

                if (attributes == FileAttributes.ReadOnly)
                {
                    vs.SourceControl.CheckOutItem(itemPath);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

        public static void Checkout(Project p)
        {
            Checkout(p.DTE, Utils.SafeToString(p.Properties.Item("LocalPath").Value) + Utils.SafeToString(p.Properties.Item("FileName").Value));
        }

        public static void Checkout(ProjectItem pi)
        {
            Checkout(pi.DTE, Utils.SafeToString(pi.Properties.Item("LocalPath").Value));
        }
    }
}
